package com.dfl.gankio.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.dfl.gankio.extend.obtainViewModel
import com.qmuiteam.qmui.arch.QMUIFragment

abstract class BaseFragment<VM : BaseViewModel> : QMUIFragment() {

    protected lateinit var viewModel: VM

    override fun onCreateView(): View {
        val view = LayoutInflater.from(activity).inflate(getLayoutId(), null)
        return view
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        viewModel = obtainViewModel(getViewModelClass())
        initView(view)
        initData()
    }


    abstract fun getViewModelClass(): Class<VM>

    abstract fun getLayoutId(): Int

    abstract fun initView(view: View)

    abstract fun initData()

}